package com.tedu.ds.sessionAndMessage.controller;

import com.tedu.ds.base.response.JsonResult;
import com.tedu.ds.sessionAndMessage.pojo.dto.MessageParam;
import com.tedu.ds.sessionAndMessage.pojo.dto.MessageQuery;
import com.tedu.ds.sessionAndMessage.pojo.dto.SessionParam;
import com.tedu.ds.sessionAndMessage.pojo.dto.SessionQuery;
import com.tedu.ds.sessionAndMessage.service.SessionAndMessageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/v1/webSessionMessage")
@Api(tags = "会话模块")
public class SessionAndMessageController {
    @Autowired
    private SessionAndMessageService sessionAndMessageService;

    @PostMapping("/session/select")
    @ApiOperation("查询会话功能")
    public JsonResult sessionSelect(@RequestBody SessionQuery sessionQuery){
        return JsonResult.ok(sessionAndMessageService.sessionSelect(sessionQuery));
    }

    @PostMapping("/message/select")
    @ApiOperation("查询消息功能")
    public JsonResult messageSelect(@RequestBody MessageQuery messageQuery){
        return JsonResult.ok(sessionAndMessageService.messageSelect(messageQuery));
    }

    @PostMapping("/session/save")
    @ApiOperation("新增和更新会话信息")
    public JsonResult sessionSave(@RequestBody SessionParam sessionParam){
        sessionAndMessageService.saveSession(sessionParam);
        return JsonResult.ok();
    }

    @PostMapping("/message/save")
    @ApiOperation("新增和更新信息")
    public JsonResult messageSave(@RequestBody MessageParam messageParam){
        sessionAndMessageService.saveMessage(messageParam);
        return JsonResult.ok();
    }

    @DeleteMapping("/session/delete/{id}")
    @ApiOperation("删除会话")
    public JsonResult sessionDeleteById(@PathVariable Integer id){
        sessionAndMessageService.deleteSession(id);
        return JsonResult.ok();
    }

    @DeleteMapping("/message/delete")
    @ApiOperation("批量删除消息")
    public JsonResult messageDeleteByIds(@RequestBody List<Long> ids){
        sessionAndMessageService.deleteMessage(ids);
        return JsonResult.ok();
    }
}
